package com.huawei.petSystemdemo.data;

import android.content.Intent;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huawei.petSystemdemo.GlobalViewModel;
import com.huawei.petSystemdemo.bean.Order;
import com.huawei.petSystemdemo.utils.MyRequest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import static com.huawei.petSystemdemo.GlobalViewModel.getGlobal;

public class CartRepository {

    public static void deleteShopping(List<Integer> cartIds, Consumer<String> callback) {
        String json = JSON.toJSONString(cartIds);
        Map<String, Object> resBody = new HashMap<>();
        resBody.put("json", json);
        MyRequest.post("/shopping/deleteShopping", resBody, new Consumer<String>() {
            @Override
            public void accept(String json) {

                JSONObject obj = JSON.parseObject(json);
                boolean success = obj.getBoolean("success");
                String data = obj.getString("data");
                if (success)
                {
                    if (callback != null)
                        callback.accept(data);
                }
                else
                {

                }
            }
        });
    }

    public static void saveOrder(int user_id, double money, List<Integer> listPetId, int state, int order_add, Consumer<String> callback) {
        Map<String, Object> resBody = new HashMap<>();
        resBody.put("user_id", user_id);
        resBody.put("money", money);
        String json = JSON.toJSONString(listPetId);
        resBody.put("json", json);
        resBody.put("state", state);
        resBody.put("add", order_add);
        MyRequest.post("/order/saveOrder", resBody, new Consumer<String>() {
            @Override
            public void accept(String json) {
                JSONObject obj = JSON.parseObject(json);
                boolean success = obj.getBoolean("success");
                String data = obj.getString("data");
                if (success)
                {
                    if (callback != null)
                        callback.accept(data);
                }
                else
                {

                }
            }
        });
    }
}
